<?php
namespace app\web\controller;

use app\common\logic\CommonLogic;
use app\common\logic\DriverLogic;
use app\common\logic\OrderLogic;
use app\common\util\ErrorCode;

class CronController
{
    public $returnData = [];
    public function __construct()
    {
        $this->returnData = ErrorCode::code("success");
    }

    public function cronTab($_type){
        if($_type == "commonHandle"){ // 每10秒触发1次
            $orderLogic = new OrderLogic();
            $orderLogic->startCancelOrderJobs(); // 取消订单定时处理
            $orderLogic->orderExpireJobs(); // 订单定时处理预约即将过期的
        }else if($_type == "orderCommission"){ // 每1天（每天0点0分执行一次）
            // 线路分佣
            $driverLogic = new DriverLogic();
            $driverLogic->getHandleOrderCommission();
        }
        return $this->return_result($this->returnData);
    }

    public function return_result($data, $text = '')
    {
        if(!is_array($data['msg']) && $text && strpos($data['msg'], "%s") !== false){
            $data['msg'] = sprintf($data['msg'], $text);
        }
        return json($data);
    }

    //空操作
    public function _empty()
    {
        return $this->return_result(ErrorCode::$errorCode['method_not_exist']);
    }
}
